/*    */ package com.hp.bon.sgw.core.channel.handler;
/*    */ 
/*    */ /*    */ import org.slf4j.Logger;
/*    */ import org.slf4j.LoggerFactory;

import com.hp.bon.sgw.bean.ProtocalConvertResult;
/*    */ import com.hp.bon.sgw.bean.XmlMessage;
/*    */ import com.hp.bon.sgw.convert.DataExchangerImpl;
/*    */ import com.hp.bon.sgw.core.CallParam;
/*    */ import com.hp.bon.sgw.core.channel.DCCChannel;
/*    */ import com.hp.bon.sgw.threads.TaskManager;
/*    */ import com.hp.bon.sgw.util.dcc.DccAvpHelper;
import com.hp.bon.sgw.wh.service.LimitConfigService;
import com.hp.bon.sgw.wh.service.UsageLimitConfigService;
/*    */ import com.hp.ocs.diameter.message.AVP;
/*    */ import com.hp.ocs.diameter.message.AVP_Unsigned32;
/*    */ import com.hp.ocs.diameter.message.Message;
/*    */ import com.hp.ocs.diameter.node.Peer;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class DCCAsynCallHandler
/*    */   implements IAsynCallHandler
/*    */ {
/* 21 */   private static final Logger logger = LoggerFactory.getLogger(DCCAsynCallHandler.class);
/*    */   Message request;
/*    */   Peer peer;
/*    */   DCCChannel dccChannel;
/*    */ 
/*    */   public DCCAsynCallHandler(Message request, Peer peer, DCCChannel dccChannel)
/*    */   {
/* 24 */     this.dccChannel = dccChannel;
/* 25 */     this.request = request;
/* 26 */     this.peer = peer;
/*    */   }
/*    */ 
/*    */   public void onCallResult(CallParam callParam)
/*    */   {
/* 45 */     Message answer = new Message();
/* 46 */     answer.prepareResponse(this.request);
/*    */ 
/* 48 */     Object response = null;
/*    */ 
/* 50 */     if (callParam.getResponse() != null)
/* 51 */       response = callParam.getResponse();
/* 52 */     else if (callParam.getRecvResponse() != null) {
/* 53 */       response = callParam.getRecvResponse();
/*    */     }
/*    */ 
/* 56 */     if (response == null) {
/* 57 */       this.request.getDictionary().prepareResponseAVP(answer);
/* 58 */       if ((callParam.getFromNode().getNodeType() == 1) && ((callParam.getRetCode() == 11203) || (callParam.getRetCode() == 11205))) {
/* 59 */         callParam.setRetCode(10022);
/*    */       }

/* 61 */       int serviceResultCode = callParam.getRetCode();
			   int resultCode = serviceResultCode > 10000 ? 2001 : serviceResultCode;
			   if(serviceResultCode==UsageLimitConfigService.getIntValue("DIAMETER_RESULT_TOO_BUSY", 501)||serviceResultCode==LimitConfigService.getIntValue("DIAMETER_RESULT_TOO_BUSY", 501)){
					 resultCode = 2001;
			   }
/* 62 */       
/* 63 */       answer.add(new AVP_Unsigned32(268, resultCode));
/* 64 */       answer.add(DccAvpHelper.genDefaultServiceResultAVP(serviceResultCode));
/* 65 */       this.dccChannel.addOurHostAndRealm(answer);
/* 66 */       answer.header().setError(true);
/*    */     }
/* 68 */     else if ((response instanceof Message)) {
/* 69 */       DccAvpHelper.copyMessageAVP((Message)response, answer);
/* 70 */     } else if ((response instanceof XmlMessage)) {
/* 71 */       this.request.getDictionary().prepareResponseAVP(answer);
/*    */ 
/* 73 */       ProtocalConvertResult result = DataExchangerImpl.getInstance().convertToCCAResult(callParam.getServiceContextId(), ((XmlMessage)response).getDataElement());
/* 74 */       if (result.getRetCode() != 0) {
/* 75 */         logger.warn(callParam.getSessionId() + ",convert SgwQueryAck to AVP failed:" + result.getErrMsg());
/* 76 */         answer.add(new AVP_Unsigned32(268, 5012));
/*    */       } else {
/* 78 */         answer.add(new AVP_Unsigned32(268, 2001));
/* 79 */         answer.add((AVP)result.getResult());
/*    */       }
/*    */ 
/*    */     }
/*    */ 
/* 84 */     callParam.setResponse(answer);
/* 85 */     this.dccChannel.sendAnswer(this.peer, callParam);
/* 86 */     TaskManager.taskProcess(callParam);
/*    */   }
/*    */ 
/*    */   public int getProtocolType()
/*    */   {
/* 91 */     return 1;
/*    */   }
/*    */ }

/* Location:           C:\Users\think\Desktop\sgw_2.1.jar
 * Qualified Name:     com.hp.bon.sgw.core.channel.handler.DCCAsynCallHandler
 * JD-Core Version:    0.6.1
 */